package org.alex.mqtt.common.remote;


import io.netty.channel.Channel;
import org.alex.mqtt.common.log.MqttLogger;
import org.slf4j.Logger;

import java.net.SocketAddress;

public class RemotingHelper {

    private static final Logger log = MqttLogger.remotingLog;

    public static String getRemoteAddr(Channel channel) {
        if (null == channel) {
            return "";
        }
        SocketAddress remote = channel.remoteAddress();
        final String addr = remote != null ? remote.toString() : "";
        if (addr.length() > 0) {
            int index = addr.lastIndexOf("/");
            if (index >= 0) {
                return addr.substring(index + 1);
            }

            return addr;
        }
        return "";
    }
}
